﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace WindowsFormsApplication2
{
    public partial class FormWidth : Form
    {
        public FormWidth()
        {
            InitializeComponent();
        }

        public int FontSize
        {
            get
            {
                return Int32.Parse(txtWidth.Text);
            }
            set
            {
                if (value > 300 || value < 20)
                {
                    throw new Exception(" Khong Hop Le!");

                }
                txtWidth.Text = value.ToString();
            }
        }

        private void txtWidth_Validating(object sender, CancelEventArgs e)
        {
            try
            {
                int width = Int32.Parse(txtWidth.Text);
                if (width < 20 || width > 300)
                {
                    throw new Exception("khong hop le!");
                }
                // Thanh cong
                // Xoa loi
                errorProvider1.SetError((Control)txtWidth, "");
                // Cho phep xu ly tiep
                e.Cancel = false;

            }
            catch (FormatException ee1) // ep kieu khong thanh cong
            {
                // Thiet lap loi
                errorProvider1.SetError((Control)txtWidth, "Ban phai nhap ten cho kich thuoc!");
                // Bat phai nhap lai
                e.Cancel = true;
            }
            catch (Exception ee2)
            {
                // Thiet lap loi
                errorProvider1.SetError((Control)txtWidth, ee2.Message);
                // Bat phai nhap lai
                e.Cancel = true;
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Yes;
            this.Close();
        }

        private void btnCANCEL_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.No;
            this.Close();
        }
    }
}
